home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / error.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  13KB  |  378 lines

  1. /***********************************************************************/
  2. /* ERROR.C - Function to display error messages.                       */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1995 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Id: error.c 2.0 1995/01/26 16:30:56 MH Release MH $
  41. */
  42.  
  43. #include <stdio.h>
  44.  
  45. #include "the.h"
  46. #include "proto.h"
  47.  
  48. /*-------------------------- global   data -----------------------------*/
  49.  
  50. CHARTYPE last_message[160]="";        /* contents of last error message */
  51. static int errors_displayed=0;            /* number of errors displayed */
  52. static int last_row_displayed=(-1);/* last row in which error displayed */
  53. static LINE *first_error=NULL;                   /* first error message */
  54. static LINE *last_error=NULL;                    /* last error message */
  55.  
  56. #ifdef PROTO
  57. static void open_msgline(CHARTYPE,short,ROWTYPE);
  58. #else
  59. static void open_msgline();
  60. #endif
  61. /***********************************************************************/
  62. #ifdef PROTO
  63. void display_error(unsigned short err_num,CHARTYPE *mess,bool ignore_bell)
  64. #else
  65. void display_error(err_num,mess,ignore_bell)
  66. unsigned short err_num;
  67. CHARTYPE *mess;
  68. bool ignore_bell;
  69. #endif
  70. /***********************************************************************/
  71. {
  72. /*------------------------- external data -----------------------------*/
  73.  extern WINDOW *error_window;
  74.  extern bool error_on_screen;
  75.  extern bool in_profile;
  76.  extern bool ETMODEx;
  77.  extern bool BEEPx;
  78.  extern CHARTYPE number_of_files;
  79. /*--------------------------- local data ------------------------------*/
  80.  
  81. static CHARTYPE *error_message[] =
  82. {
  83.  (CHARTYPE *)"",
  84.  (CHARTYPE *)"Error 0001: Invalid operand:",
  85.  (CHARTYPE *)"Error 0002: Too many operands",
  86.  (CHARTYPE *)"Error 0003: Too few operands",
  87.  (CHARTYPE *)"Error 0004: Invalid number:",
  88.  (CHARTYPE *)"Error 0005: Numeric operand too small",
  89.  (CHARTYPE *)"Error 0006: Numeric operand too large",
  90.  (CHARTYPE *)"Error 0007: Length of operand > 10",
  91.  (CHARTYPE *)"Error 0008: Invalid or protected file",
  92.  (CHARTYPE *)"Error 0009: File not found",
  93.  (CHARTYPE *)"Error 0010: Path not found",
  94.  (CHARTYPE *)"Error 0011: File not found in THE_MACRO_PATH:",
  95.  (CHARTYPE *)"Error 0012: Margins settings are inconsistant",
  96.  (CHARTYPE *)"Error 0013: Invalid key name:",
  97.  (CHARTYPE *)"",
  98.  (CHARTYPE *)"",
  99.  (CHARTYPE *)"",
  100.  (CHARTYPE *)"Error 0017: Target not found",
  101.  (CHARTYPE *)"Error 0018: Invalid line name",
  102.  (CHARTYPE *)"",
  103.  (CHARTYPE *)"",
  104.  (CHARTYPE *)"Error 0021: Invalid command:",
  105.  (CHARTYPE *)"Error 0022: File has been changed - use QQUIT to really quit",
  106.  (CHARTYPE *)"Error 0023: Help file not found:",
  107.  (CHARTYPE *)"Error 0024: Invalid profile command:",
  108.  (CHARTYPE *)"Error 0025: Error accessing REXX variable",
  109.  (CHARTYPE *)"",
  110.  (CHARTYPE *)"",
  111.  (CHARTYPE *)"",
  112.  (CHARTYPE *)"Error 0029: Cannot edit -",
  113.  (CHARTYPE *)"Error 0030: Memory shortage",
  114.  (CHARTYPE *)"Error 0031: File already exists - use FFILE/SSAVE",
  115.  (CHARTYPE *)"Error 0032: Invalid hexadecimal or decimal value",
  116.  (CHARTYPE *)"",
  117.  (CHARTYPE *)"",
  118.  (CHARTYPE *)"",
  119.  (CHARTYPE *)"Error 0036: No lines changed",
  120.  (CHARTYPE *)"Error 0037: Operand too long:",
  121.  (CHARTYPE *)"Error 0038: Improper cursor position",
  122.  (CHARTYPE *)"Error 0039: No remembered operand available",
  123.  (CHARTYPE *)"Error 0040: /bin/sh cannot suspend this process",
  124.  (CHARTYPE *)"Error 0041: Invalid SOS command:",
  125.  (CHARTYPE *)"Error 0042: Invalid SET command:",
  126.  (CHARTYPE *)"",
  127.  (CHARTYPE *)"Error 0044: No marked block",
  128.  (CHARTYPE *)"Error 0045: Marked block not in current file",
  129.  (CHARTYPE *)"",
  130.  (CHARTYPE *)"Error 0047: Operation invalid for line blocks",
  131.  (CHARTYPE *)"Error 0048: Operation invalid for box blocks",
  132.  (CHARTYPE *)"",
  133.  (CHARTYPE *)"Error 0050: Invalid move location",
  134.  (CHARTYPE *)"",
  135.  (CHARTYPE *)"",
  136.  (CHARTYPE *)"Error 0053: Valid only when issued from a REXX macro",
  137.  (CHARTYPE *)"Error 0054: REXX interpreter returned an error",
  138.  (CHARTYPE *)"Error 0055: No lines sorted",
  139.  (CHARTYPE *)"Error 0056: Action invalid in read-only mode.",
  140.  (CHARTYPE *)"Error 0057: Disk full error",
  141.  (CHARTYPE *)"",
  142.  (CHARTYPE *)"",
  143.  (CHARTYPE *)"Error 0060: Line name not found:",
  144.  (CHARTYPE *)"Error 0061: Colour support not available:",
  145.  (CHARTYPE *)"",
  146.  (CHARTYPE *)"Error 0063: Invalid cursor line or column",
  147.  (CHARTYPE *)"Error 0064: Line not reserved",
  148.  (CHARTYPE *)"",
  149.  (CHARTYPE *)"Error 0066: Invalid match position",
  150.  (CHARTYPE *)"Error 0067: Invalid match character",
  151.  (CHARTYPE *)"Error 0068: Matching character not found",
  152.  (CHARTYPE *)"Error 0069: Invalid character",
  153.  (CHARTYPE *)"",
  154.  (CHARTYPE *)"",
  155.  (CHARTYPE *)"",
  156.  (CHARTYPE *)"",
  157.  (CHARTYPE *)"",
  158.  (CHARTYPE *)"",
  159.  (CHARTYPE *)"",
  160.  (CHARTYPE *)"",
  161.  (CHARTYPE *)"",
  162.  (CHARTYPE *)"",
  163.  (CHARTYPE *)"",
  164.  (CHARTYPE *)"",
  165.  (CHARTYPE *)"",
  166.  (CHARTYPE *)"",
  167.  (CHARTYPE *)"",
  168.  (CHARTYPE *)"",
  169.  (CHARTYPE *)"",
  170.  (CHARTYPE *)"Error 0087: Cursor line not in scope"
  171. };
  172.  LINE *curr_error=NULL;
  173.  register int i=0;
  174. /*--------------------------- processing ------------------------------*/
  175. #ifdef TRACE
  176.  trace_function("error.c:   display_error");
  177. #endif
  178. /*---------------------------------------------------------------------*/
  179. /* If msgmode is off, don't display any errors.                        */
  180. /*---------------------------------------------------------------------*/
  181.  if (CURRENT_VIEW != NULL)
  182.    {
  183.     if (!CURRENT_VIEW->msgmode_status)
  184.       {
  185. #ifdef TRACE
  186.        trace_return();
  187. #endif
  188.        return;
  189.       }
  190.    }
  191.  sprintf(last_message,"%s %s",error_message[err_num],mess);
  192.  
  193. #ifdef MSWIN
  194.  {
  195.  char hdr[512];
  196.  if(in_profile)
  197.       {
  198.       if(!error_on_screen)
  199.            {
  200.            if(number_of_files == 0)
  201.                 sprintf(hdr,"*** Messages from profile file  ***\n");
  202.                 else
  203.                 sprintf(hdr,"*** Messages from profile file for ***\n%s%s\n",
  204.                          CURRENT_FILE->fpath,CURRENT_FILE->fname);
  205.            }
  206.       error_on_screen = TRUE;
  207.       Operator("%s%s",hdr,last_message);
  208.       return;
  209.       }
  210.  }
  211. #else
  212.  if (in_profile)
  213.    {
  214.     if (!error_on_screen)
  215.       {
  216.        if (number_of_files == 0)
  217.           fprintf(stderr,"*** Messages from profile file  ***\n");
  218.        else
  219.           fprintf(stderr,"*** Messages from profile file for %s%s ***\n",
  220.                          CURRENT_FILE->fpath,CURRENT_FILE->fname);
  221.       }
  222.     error_on_screen = TRUE;
  223.     fprintf(stderr,"%s\n",last_message);
  224. #ifdef TRACE
  225.     trace_return();
  226. #endif
  227.     return;
  228.    }
  229. #endif
  230.  error_on_screen = TRUE;
  231. /*---------------------------------------------------------------------*/
  232. /* Calculate number of errors. This determines size of window to be    */
  233. /* created.                                                            */
  234. /*---------------------------------------------------------------------*/
  235.  errors_displayed = min(CURRENT_VIEW->msgline_rows,errors_displayed+1);
  236. /*---------------------------------------------------------------------*/
  237. /* Create the window errors_displayed rows long.                       */
  238. /*---------------------------------------------------------------------*/
  239.  open_msgline(CURRENT_VIEW->msgline_base,CURRENT_VIEW->msgline_off,errors_displayed);
  240. /*---------------------------------------------------------------------*/
  241. /* Append the current messageto the end of the error linked list.      */
  242. /*---------------------------------------------------------------------*/
  243.  last_error = lll_add(first_error,last_error,sizeof(LINE));
  244.  if (last_error == NULL)
  245.    {
  246.     return;
  247.    }
  248.  last_error->line = (CHARTYPE *)(*the_malloc)((strlen(last_message)+1)*sizeof(CHARTYPE));
  249.  if (last_error->line == NULL)
  250.    {
  251.     return;
  252.    }
  253.  strcpy(last_error->line,last_message);
  254.  last_error->length = strlen(last_message);
  255.  if (first_error == NULL)
  256.     first_error = last_error;
  257.  curr_error = last_error;
  258. /*---------------------------------------------------------------------*/
  259. /* For all errors that are to be displayed, display them starting from */
  260. /* the bottom of the window.                                           */
  261. /*---------------------------------------------------------------------*/
  262.  for (i=errors_displayed-1;i>-1;i--)
  263.    {
  264.     wmove(error_window,i,0);
  265.     my_wclrtoeol(error_window);
  266.     if (ETMODEx)
  267.        mvwaddstr(error_window,i,0,curr_error->line);
  268.     else
  269.        put_string(error_window,i,0,curr_error->line,curr_error->length);
  270.     curr_error = curr_error->prev;
  271.    }
  272. #if !defined(NO_BEEP)
  273.  if (BEEPx
  274.  && !ignore_bell)
  275.     beep();
  276. #endif
  277.  wrefresh(error_window);
  278. #ifdef TRACE
  279.  trace_return();
  280. #endif
  281.  return;
  282. }
  283. /***********************************************************************/
  284. #ifdef PROTO
  285. static void open_msgline(CHARTYPE base,short off,ROWTYPE rows)
  286. #else
  287. static void open_msgline(base,off,rows)
  288. CHARTYPE base;
  289. short off;
  290. ROWTYPE rows;
  291. #endif
  292. /***********************************************************************/
  293. {
  294. /*------------------------- external data -----------------------------*/
  295.  extern WINDOW *error_window;
  296.  extern bool error_on_screen;
  297. /*--------------------------- local data ------------------------------*/
  298.  int start_row=0;
  299. /*--------------------------- processing ------------------------------*/
  300. #ifdef TRACE
  301.  trace_function("error.c:   open_msgline");
  302. #endif
  303.  start_row = calculate_actual_row(base,off,CURRENT_SCREEN.screen_rows);
  304.  if (base == POSITION_BOTTOM)
  305.     start_row = start_row - rows + 1;
  306.  if (error_window != NULL)
  307.     delwin(error_window);
  308.  error_window = newwin(rows,CURRENT_SCREEN.screen_cols,CURRENT_SCREEN.screen_start_row+start_row,CURRENT_SCREEN.screen_start_col);
  309.  wattrset(error_window,set_colour(CURRENT_FILE->attr+ATTR_MSGLINE));
  310. #ifdef TRACE
  311.  trace_return();
  312. #endif
  313.  return;
  314. }
  315. /***********************************************************************/
  316. #ifdef PROTO
  317. void clear_msgline(void)
  318. #else
  319. void clear_msgline()
  320. #endif
  321. /***********************************************************************/
  322. {
  323. /*------------------------- external data -----------------------------*/
  324.  extern WINDOW *error_window;
  325.  extern bool error_on_screen;
  326. /*--------------------------- local data ------------------------------*/
  327. /*--------------------------- processing ------------------------------*/
  328. #ifdef TRACE
  329.  trace_function("error.c:   clear_msgline");
  330. #endif
  331.  errors_displayed = 0;
  332.  error_on_screen = FALSE;
  333.  if (error_window != (WINDOW *)NULL)
  334.    {
  335.     delwin(error_window);
  336.     error_window = (WINDOW *)NULL;
  337.    }
  338.  lll_free(first_error);
  339.  first_error = last_error = NULL;
  340.  redraw_screen(current_screen);
  341.  doupdate();
  342. #ifdef TRACE
  343.  trace_return();
  344. #endif
  345.  return;
  346. }
  347. /***********************************************************************/
  348. #ifdef PROTO
  349. void display_prompt(CHARTYPE *prompt)
  350. #else
  351. void display_prompt(prompt)
  352. CHARTYPE *prompt;
  353. #endif
  354. /***********************************************************************/
  355. {
  356. /*------------------------- external data -----------------------------*/
  357.  extern WINDOW *error_window;
  358.  extern bool error_on_screen;
  359.  extern bool ETMODEx;
  360. /*--------------------------- local data ------------------------------*/
  361. /*--------------------------- processing ------------------------------*/
  362. #ifdef TRACE
  363.  trace_function("error.c:   display_prompt");
  364. #endif
  365.  open_msgline(CURRENT_VIEW->msgline_base,CURRENT_VIEW->msgline_off,1);
  366.  wmove(error_window,0,0);
  367.  my_wclrtoeol(error_window);
  368.  if (ETMODEx)
  369.     mvwaddstr(error_window,0,0,prompt);
  370.  else
  371.     put_string(error_window,0,0,prompt,strlen(prompt));
  372.  wrefresh(error_window);
  373. #ifdef TRACE
  374.  trace_return();
  375. #endif
  376.  return;
  377. }
  378.